package top.monddia.netty.client.client.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import top.monddia.netty.common.model.dto.MessageDto;

/**
 * Netty客户端消息处理器
 *
 * @author ZYP
 */
public class MessageHandler extends ChannelInboundHandlerAdapter {

    protected Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    public void channelRead(ChannelHandlerContext channelHandlerContext, Object msg) throws Exception {
        logger.info("Receive message: {}", msg.toString());
        // 对象类型正确则处理
        if (msg instanceof MessageDto) {

        }
        super.channelRead(channelHandlerContext, msg);
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext channelHandlerContext, Throwable throwable) {
        channelHandlerContext.close();
    }
}
